package com.atguigu.statistics.scheduled;

import com.atguigu.statistics.service.DailyService;
import com.atguigu.statistics.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

@Component
public class ScheduledTask {
    @Autowired
    private DailyService dailyService;

//    @Scheduled(cron = "0/5 * * * * ?")
//    public void task(){
//        System.out.println("====定时任务=====");
//    }

    @Scheduled(cron = "0 0 1 * * ?")//每天一点生成数据
    public void getResNum(){
        String day = DateUtil.formatDate(DateUtil.addDays(new Date(), -1));
        dailyService.insertResNum(day);
    }

}
